$(document).ready(function(){
	var url = window.location;
	var id = cw.common.getQueryString(url,"ID");
	loadT_FIXED_ASSETS_DETAIL(id);
	loadT_FIXED_ASSETS(id);
	
})
var loadT_FIXED_ASSETS = function(id,barcode){
	if( (""==id||null==id||undefined==id) && (""==barcode||null==barcode||undefined==barcode)  )
	{
		alert("非法请求，请联系管理员!");
		return;
	}
	var url = cw.common.path + '/json?action=GET_T_FA_ALLOCATE_ACTION&FA_ALLOCATE_NO='+id;
	$.post(url,{},function(data){
		if(data.success){
			var vobj=data.root.T_FA_ALLOCATE;
			if(vobj==null||vobj==''||vobj==undefined){
				alert("该资产调拨信息不存在或已被删除");
				return;
			}
			else{
				var obj = data.root.T_FA_ALLOCATE.rs[0];
				cw.common.getValue('ALLOCATE_IN_DEPARTMENT',obj.ALLOCATE_IN_DEPARTMENT_NAME,'');
				cw.common.getValue('ALLOCATE_OUT_DEPARTMENT',obj.ALLOCATE_OUT_DEPARTMENT_NAME,'');
				
				cw.common.getValue('IN_DEPARTMENT_MANAGER',obj.IN_DEPARTMENT_MANAGER_NAME,'');
				cw.common.getValue('NEW_WITH_MANANGER',obj.NEW_WITH_MANANGER_NAME,'');
				cw.common.getValue('OUT_DEPARTMENT_MANAGER',obj.OUT_DEPARTMENT_MANAGER_NAME,'');
				cw.common.getValue('OLD_WITH_MANANGER',obj.OLD_WITH_MANANGER_NAME,'');
							
			}
		}
		else{
			alert(data.errors.errmsg);
		}
	},'json');
}

//载入资产详细信息
function loadT_FIXED_ASSETS_DETAIL(id){
	var url = cw.common.path + '/json?action=QUERY_T_FA_DETAILBY_PAGER_ACTION';
	url += "&ID="+id;
	var xmlname = "T_FA_ALLOCATE_DETAIL";
	var pagePanel='#T_FIXED_ASSETS_DETAIL_pager';
	var result='#T_FIXED_ASSETS_DETAIL_LIST';
	var pageSize=10000;
	var defaultHtml='<li><em style="text-align: center;width:100%">没有搜索到您要查询的数据...</em></li>';
	cw.common.changePage(url,pageSize,xmlname,result,fn_queryT_FIXED_ASSETS_DETAILLIST,pagePanel,defaultHtml);
}
var fn_queryT_FIXED_ASSETS_DETAILLIST = function(obj,result,i){	
	
	var str='<tr>';
	str+='<td  width="6%" align="center">'+obj.FA_ALLOCATE_DETAIL_NO+'</td>';//编号
    str+='<td  width="9%" align="center">'+obj.FA_ALLOCATE_NO+'</td>';//资产编号
    str+='<td  width="9%" align="center">'+obj.FIXED_ASSETS_NAME+'</td>';//资产名称
    str+='<td  width="12%" align="center">'+obj.BRAND+'</td>';//型号、规格
    str+='<td  width="12%" align="center">'+obj.ANCILARY_ITEM+'</td>';//附属物品
    str+='<td  width="6%" align="center">'+obj.QUANTITY+'</td>';//数量
    str+='<td  width="9%" align="center">'+obj.SUPPLIERS_NO_NAME+'</td>';//厂家
    str+='<td  width="9%" align="center">'+obj.FACTORY_NO+'</td>';//出厂编号
    str+='<td  width="28%" align="center">'+obj.REMARK+'</td>';//转移原因 ALLOCATE_REASON
	str+='</tr>';
	
	$(result).append(str);
}
//批量删除
function batchDel(){
	if(getCheckedNum('check')==0){
		alert('请选择要删除的资产条码');
		return;
	}
	if(!confirm('确定要删除资产吗？')){
		return;
	}
	var barcodeA = getCheckedVal('check').split(',');
	$.post(cw.common.path + '/json',
		{
			action : 'BATCH_DELETE_T_FIXED_ASSETS_DETAIL_ACTION',
			BARCODE : barcodeA
		}, function(data){
			if (data.success) {
				for(var i=0;i<barcodeA.length;i++)
				{
					$("#bar_"+barcodeA[i]).remove();
				}
				alert('批量删除低值易耗品成功');
			} else {
				alert(data.errors.errmsg);
			}
		}, 'json');
}
//批量删除
function del(barcode){
	$.post(cw.common.path + '/json',
		{
			action : 'DELETE_T_FIXED_ASSETS_DETAIL_ACTION',
			BARCODE : barcode
		}, function(data){
			if (data.success) {
					$("#bar_"+barcode).remove();
					alert('批量删除低值易耗品成功');
			} else {
				alert(data.errors.errmsg);
			}
		}, 'json');
}